home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Systemmonitors / RSys / RSysSrc.lha / RSysClip.c < prev    next >
C/C++ Source or Header  |  1993-09-19  |  3KB  |  182 lines

  1. /*
  2. ***************************************************************************
  3. *
  4. * Datei:
  5. *      RSysClip.c
  6. *
  7. * Inhalt:
  8. *
  9. *      --- Globale Routinen ---
  10. *
  11. *    void RSysEntryToClip ( void );
  12. *    void RSysListToClip ( void );
  13. *    void SaveListToClip ( struct List *list , char *text );
  14. *
  15. *      --- Lokale  Routinen ---
  16. *
  17. *
  18. * Bemerkungen:
  19. *      Unterstützung des ClipBoard-Devices.
  20. *
  21. * Erstellungsdatum:
  22. *      07-Jul-93     Rolf Böhme
  23. *
  24. * Änderungen:
  25. *      07-Jul-93     Rolf Böhme      Erstellung
  26. *
  27. ***************************************************************************
  28. */
  29.  
  30. #include "RSys.h"
  31.  
  32. void
  33. SaveListToClip(struct List *list,char *text)
  34. {
  35.     char Success = FALSE;
  36.     struct Node *node;
  37.     int len;
  38.     struct IFFHandle *Handle;
  39.  
  40.     DPOS;
  41.  
  42.     if (IFFParseBase = OpenLibrary ((UBYTE *)"iffparse.library", 0L))
  43.     {
  44.         if(Handle = AllocIFF())
  45.         {
  46.             if(Handle->iff_Stream = (ULONG)OpenClipboard(PRIMARY_CLIP))
  47.             {
  48.                 InitIFFasClip(Handle);
  49.  
  50.                 if(!OpenIFF(Handle,IFFF_WRITE))
  51.                 {
  52.                     if(!PushChunk(Handle,ID_FTXT,ID_FORM,IFFSIZE_UNKNOWN))
  53.                     {
  54.                         if(!PushChunk(Handle,0,ID_CHRS,IFFSIZE_UNKNOWN))
  55.                         {
  56.                             if(list != NULL)
  57.                             {
  58.                                 for(node = list->lh_Head; node->ln_Succ; node = node->ln_Succ)
  59.                                 {
  60.                                     len = strlen(node->ln_Name);
  61.  
  62.                                     if(WriteChunkBytes(Handle,node->ln_Name,len) != len) break;
  63.  
  64.                                     if(WriteChunkBytes(Handle,"\n",1) != 1) break;
  65.                                 }
  66.                             }
  67.                             else
  68.                             {
  69.                                 len = strlen(text);
  70.  
  71.                                 if(WriteChunkBytes(Handle,(STRPTR)text,len) != len) Success = FALSE;
  72.                             }
  73.  
  74.                             if(!PopChunk(Handle)) Success = TRUE;
  75.                         }
  76.                     }
  77.  
  78.                     if(Success)
  79.                         if(PopChunk(Handle)) Success = FALSE;
  80.  
  81.                     CloseIFF(Handle);
  82.                 }
  83.  
  84.                 CloseClipboard((struct ClipboardHandle *)Handle->iff_Stream);
  85.             }
  86.  
  87.             FreeIFF(Handle);
  88.         }
  89.  
  90.         CloseLibrary (IFFParseBase);
  91.     }
  92.    else ErrorHandle("iffparse.library", LIBRARY_ERR, OPEN_FAIL, NO_KILL);
  93.  
  94.     if(!Success) ErrorHandle("Unit 0", CLIPBOARD_ERR, WRITE_FAIL, NO_KILL);
  95.  
  96.     return;
  97. }
  98.  
  99. void
  100. RSysListToClip(void)
  101. {
  102.    HandleHelp(MN_RSysListToClip);
  103.  
  104.     PrintInfo("Saving List to clipboard", SPEAK, 0);
  105.  
  106.     SaveListToClip(&ListeLVList, NULL);
  107.  
  108.     PrintStatistics();
  109.  
  110.     return;
  111. }
  112.  
  113. void
  114. RSysEntryToClip(void)
  115. {
  116.     register struct IntuiMessage *message;
  117.     APTR object;
  118.     ULONG class,
  119.             code;
  120.  
  121.     DPOS;
  122.  
  123.    HandleHelp(MN_RSysEntryToClip);
  124.  
  125.     Flags.quit_clip = 0;
  126.  
  127.     PrintInfo("Select list entry (ESC to cancel)", SPEAK, 0);
  128.  
  129.     do
  130.     {
  131.             /*
  132.              * Warten auf folgende Events:
  133.              * - ^C wurde eingegeben
  134.              * - Events vom Hauptfenster
  135.              */
  136.         Wait(1L << SysWnd->UserPort->mp_SigBit);
  137.  
  138.         while ((message = (struct IntuiMessage *) GT_GetIMsg(SysWnd->UserPort)) != NULL)
  139.         {
  140.                 /*
  141.                  * Die wichtigsten Daten werden aus der erhaltenen
  142.                  * Nachricht kopiert.
  143.                  */
  144.             object = message->IAddress;
  145.             class = message->Class;
  146.             code = message->Code;
  147.  
  148.                 /*
  149.                  * Die Nachricht wird sofort beantwortet, damit
  150.                  * Intuition nicht länger als notwendig auf eine
  151.                  * Antwort wartet.
  152.                  */
  153.             GT_ReplyIMsg(message);
  154.  
  155.             if(class == IDCMP_GADGETUP)
  156.             {
  157.                 if(((struct Gadget *)object)->GadgetID == GD_ListeLV)
  158.                 {
  159.                     struct Node *node;
  160.  
  161.                     if(node = GetNode(&ListeLVList,code))
  162.                     {
  163.                         SaveListToClip(NULL, node->ln_Name);
  164.                         Flags.quit_clip = 1;
  165.                     }
  166.                 }
  167.             }
  168.  
  169.             if((class == IDCMP_VANILLAKEY) && (code == ESC))
  170.             {
  171.                 Flags.quit_clip = 1;
  172.                 PrintInfo("Selection aborted!",SPEAK, SEC);
  173.             }
  174.         }
  175.     } while(NOT(Flags.quit_clip));
  176.  
  177.     PrintStatistics();
  178.  
  179.     return;
  180. }
  181.  
  182.